// components/pick-date-range/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
     show: {default:false,type: Boolean}
  },

  /**
   * 组件的初始数据
   */
  data: {
    startDate: new Date(),
    endDate: new Date(),
    showStartDate: false,
    showEndDate: false,
    pickStartDate: new Date(),
    pickEndDate: new Date(),
  },

  observers:{
    'show': function(show) {
      this.setData({showStartDate: show})
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onStartDatePick(e) {
      console.log('onStartDatePick',e.detail)
      this.setData({
        showStartDate: false,
        showEndDate: true,
        startDate: e.detail
      })
    },
    onEndDatePick(e) {
      console.log('onEndDatePick',e)
        this.setData({
          showEndDate: false,
          endDate: e.detail
        })
        
        this.triggerEvent('picked', {startDate:this.data.startDate, endDate:this.data.endDate});

    },
    onCancelStartPick() {
        this.setData({
          showStartDate: false,
          pickStartDate : this.data.startDate
        })

        this.triggerEvent('cancel');
    },
    onCancelEndPick() {
        
        this.setData({
          showEndDate: false,
          pickEndDate: this.data.endDate
        })
        this.triggerEvent('cancel');
    }
  }
})
